//
//  KSHeadView.swift
//  ZeroShare
//
//  Created by July on 2020/3/22.
//  Copyright © 2020 saeipi. All rights reserved.
//

import UIKit

class KSHeadView: UIView {
    var leftButton:UIButton?
    var rightButton:UIButton?
    var timeBool:Bool = false
    var typeBool:Bool = false
    var myHeadBlock:((String,Bool)->())?
    override init(frame: CGRect) {
        super.init(frame: frame)
        createUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func createUI(){
        for i in 0...1{
            let leftButton = UIButton.init(frame: CGRect.init(x: i*80, y: 0, width: 80, height: 40))
            leftButton.titleLabel?.font = UIFont.systemFont(ofSize: 14)
            self.addSubview(leftButton)
            leftButton.tag = 10+i
            if i == 0 {
                leftButton.setTitle("5分", for: .normal)
                leftButton.setTitleColor(UIColor.init(hexStr: "F1B11B"), for: .normal)
                self.leftButton = leftButton
            }else{
                leftButton.setTitle("指标", for: .normal)
                leftButton.setTitleColor(UIColor.gray, for: .normal)
                self.rightButton = leftButton
            }
            leftButton.addTarget(self, action: #selector(onClickTap(_:)), for: .touchUpInside)
        }
        
        
    }
    
    @objc func onClickTap(_ button:UIButton){
        if button.tag == 10 {
            self.typeBool = false
            if self.timeBool == false {
                leftButton?.setTitleColor(UIColor.init(hexStr: "F1B11B"), for: .normal)
                rightButton?.setTitleColor(UIColor.gray, for: .normal)
            }
            if self.myHeadBlock != nil {
                self.myHeadBlock!("time",self.timeBool)
            }
            self.timeBool = !self.timeBool
        }else if button.tag == 11 {
            self.timeBool = false
            rightButton?.setTitleColor(UIColor.init(hexStr: "F1B11B"), for: .normal)
            leftButton?.setTitleColor(UIColor.gray, for: .normal)
            if self.typeBool == false {
                if self.myHeadBlock != nil {
                    self.myHeadBlock!("type",self.typeBool)
                }
            }
            self.typeBool = !self.typeBool
        }
    }
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
